package com.cjy.runnable.demo8;

/**
 * @author Cheng JiYe
 * @description: 实现Runnable接口
 * @date 2021/4/25 1:08
 */
public class MyThread implements Runnable {
  /** 覆写run()方法 */
  @Override
  public void run() {
    for (int i = 0; i < 5; i++) {
      try {
        Thread.sleep(500);
      } catch (Exception e) {
      }
      // 取得当前线程的名字
      System.out.println(Thread.currentThread().getName() + "运行，i = " + i);
      if (i == 2) {
        System.out.print("线程礼让：");
        // 线程礼让
        Thread.yield();
      }
    }
  }
}
